l = [1, 1, 2, 2, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5]

def func(l, n):
    left = 0
    right = len(l)-1
    while left <= right:
        middle = int((right+left)/2)
        if n < l[middle]:
            right = middle-1

        elif n > l[middle]:
            left = left+1

        else:
            while 1:
                if l[middle] in l[0:middle]:
                    middle -= 1

                else:
                    return middle

    return -1


print(func(l, 1))

print(3//2)  # 取商的整数部分

# 方法2
def fun(nums, target):
    left = 0
    right = len(nums)-1
    while left <= right:
        middle = left + (right-left)//2
        if nums[middle] > target:
            right = middle - 1

        elif nums[middle] < target:
            left = middle + 1

        else:
            temp = middle
            while nums[temp] == target:
                temp -= 1
            return temp + 1

    return -1

print(func(l, 1))
print(fun(l, 1))
